import Vue from 'vue'
import VueI18n from 'vue-i18n'

import cnLocale from './lang/cn';
import uyLocale from './lang/uy';

Vue.use(VueI18n)

// 国际化文档 http://kazupon.github.io/vue-i18n/zh/guide/formatting.html
const messages = {
	cn: {
		...cnLocale,
	},
	uy: {
		...uyLocale,
	},
};

const STORAGE_CURRENT_LANGUAGE = "localeName"
// 当前用户选择过的语言
const currentLang = uni.getStorageSync(STORAGE_CURRENT_LANGUAGE);
// 默认语言为中文
const defaultLang = 'uy';

const i18n = new VueI18n({
	locale: currentLang || defaultLang,
	// locale:'uy',
	messages,
})

i18n.setLanguage = function(lang) {
	if (!lang) return;
	i18n.locale = lang
	uni.setStorageSync(STORAGE_CURRENT_LANGUAGE,lang)
	// return i18n.messages[lang];
}

Vue.prototype.$lan = i18n
export default i18n
